<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="text" id='testInput'>
    输入内容：<span id='textSpan'></span>
    <script>
        var obj = {}
        textInput = document.querySelector('#testInput')
        textSpan = document.querySelector('#textSpan')
        Object.defineProperty(obj, 'foo', {
            set: function (newValue) {
                console.log('执行')
                textInput.value = newValue;
                textSpan.innerHTML = newValue
            }
        })
        window.onload = function () {
            textInput.addEventListener('keyup', function (e) {
                obj.foo = e.target.value
            })
            setTimeout(() => {
                obj.foo = 30
            }, 5000);
        }
    </script>
</body>

</html>